package com.meiqiongproperty.yiguanjia.utils.image;

import android.graphics.Bitmap;

import com.ctrip.android.asyncimageloader.core.DisplayImageOptions;
import com.ctrip.android.asyncimageloader.core.assist.ImageLoadingListener;
import com.ctrip.android.asyncimageloader.core.assist.ImageScaleType;
import com.ctrip.android.asyncimageloader.core.display.SimpleBitmapDisplayer;
import com.meiqiongproperty.yiguanjia.R;

import java.io.File;

/**
 * @author Chen
 * @version V1.0
 * @package com.sameway.cnotes.utils.image
 * @date 17/2/6
 */
public class AsyncImageLoaderHelper {
    public static final String CACHE_FOLDER = android.os.Environment.getExternalStorageDirectory().getPath() + "/Qed/cache/";

    public static DisplayImageOptions getQedDispalyImageOption() {
        return new DisplayImageOptions.Builder()
                .showImageOnLoading(R.mipmap.ic_launcher)
                .showImageForEmptyUri(R.mipmap.ic_launcher)
                .showImageOnFail(R.mipmap.ic_launcher)
                .cacheInMemory(true).cacheOnDisc(true)
                .imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .displayer(new SimpleBitmapDisplayer()).build();
    }

    public static ImageLoadingListener getQedImageLoadingListener() {
        deleteAllFile();
        return new CImageLoadingListener();
    }

    public static void deleteAllFile() {
        String path = CACHE_FOLDER;
        deleteFile(new File(path));
    }

    public static void deleteFile(File path) {
        if (path.isDirectory()) {
            File[] files = path.listFiles();
            for (File file : files) {
                deleteFile(file);
                file.delete();
            }
        } else {
            path.delete();
        }
    }
}
